// pages/ljbj/ljbj.js

Page({

  /**
   * 页面的初始数据
   */
  data: {
    
    
  },
   getvalue: function(e){
     console.log(e.detail.value)
      this.setData({
        getvalue:e.detail.value
      })
     
   },
  fb: function() {
    if(this.data.getvalue==""||this.data.getvalue==undefined){
      wx.showToast({
        title: '请输入内容',
        icon: 'none',
        duration: 1500,
        mask:true
    })
    }else{
      wx.showToast({
        title: '发布成功',
        icon: 'succes',
        duration: 1500,
        mask:true
    })
    // wx.navigateBack({
    //   complete: (res) => {},
    //   delta: 0,
    //   fail: (res) => {},
    //   success: (res) => {},
    // })
    var date=new Date()
     
  var month=date.getMonth() + 1
        var gettime = date.getFullYear()
                + "-"// "年"
                + (month >= 10 ? month : "0"+ month)
                + "-"// "月"
                + (date.getDate() < 10 ? "0" + date.getDate() : date
                        .getDate())
                + "  "
                + (date.getHours() < 10 ? "0" + date.getHours() : date
                        .getHours())
                + ":"
                + (date.getMinutes() < 10 ? "0" + date.getMinutes() : date
                        .getMinutes())
                + ":"
                + (date.getSeconds() < 10 ? "0" + date.getSeconds() : date
                        .getSeconds());
                        // console.log(gettime)
                        this.setData({
                          time:gettime
                        })

                      console.log(this.data.time)
    wx.request({
      url: 'http://192.168.31.172:3000/createnote',
      method:"POST",
      data:{
        "openid":this.data.openid,
        "content":this.data.getvalue,
        "time":this.data.time,
          "type":0
      },
      success: (res) => {
        console.log(res)
        wx.navigateBack({
          complete: (res) => {},
          delta: 0,
          fail: (res) => {},
          success: (res) => {},
        })
       
       
      },
    })
    }
    // wx.navigateTo({
    //   url: '../index/index'
    // })
  console.log(this.data.getvalue)
   
  
                     
  },
   
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that=this
   wx.login({
     success: (res) => {
      console.log(res)
       
      wx.request({
        url: 'http://192.168.31.172:3000/getopenid',
        
        complete: (res) => {},
        data:{
          'code':res.code
        },
         method:"GET",
        success: (res) => {
          console.log(res)
          
          var openid=res.data.openid
          that.setData({
            openid:openid
          })
          wx.setStorage({
            data:openid,
            key: 'openid',
            complete: (res) => {},
            fail: (res) => {},
            success: (res) => {
              console.log(res)
            },
          })
        },
      })
     }

   })
 
   
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})